package com.hfut.eeg.common.util;

import com.hfut.eeg.common.api.CommonResult;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;

@Component
public class WriteUtil {
    @Value("${WriteUtil.address}")
    private String address;
    public CommonResult writeUtil(ArrayList<ArrayList> arr) throws IOException {
        if(arr.size()!=16){
            return CommonResult.failed("数据大小错误");
        }
        else{
            FileWriter fileWriter = new FileWriter(new File(address),true);

            for(int i=0;i<arr.get(0).size();i++){
                for(int j = 0;j<16;j++){
                    fileWriter.write(arr.get(j).get(i)+" ");
                }
                fileWriter.write("\r\n");
            }
            fileWriter.close();
            return CommonResult.success("写入成功");
        }
    }
}
